#include <stdio.h>

int main(){
    int N,M;
    scanf("%d %d",&N,&M);
    int numbers[N][N];
    for (int i=0;i<N;i++) {
        for (int j=0;j<N;j++){
            numbers[i][j]=0;
        }
    }
    for (int k=0;k<M;k++) {
        int i,j;
        scanf("%d %d",&i,&j);
        numbers[i-1][j-1]=1;
        numbers[j-1][i-1]=1;
    }
    for (int i=0;i<N;i++) {
        for (int j=0;j<N;j++){
            printf("%d",numbers[i][j]);
            if (j!=N-1)printf(" ");
        }
        printf("\n");
    } 
    for (int i=0;i<N;i++){
        int count=0;
        for (int j=0;j<N;j++){
            count+=numbers[i][j];
        }
        printf("%d",count);
        for (int j=0;j<N;j++){
            if (numbers[i][j]==1){printf(" %d",j+1);}
        }
        printf("\n");
    }
    return 0;
}